﻿<navigation:PageView x:Class="Corina.Cydee.Apphub.Views.Devices.AutoResolveConfigView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:be="clr-namespace:Corina.Interactivity.Silverlight;assembly=Corina.Interactivity.Silverlight"
                     xmlns:controls="clr-namespace:Corina.Controls.Silverlight;assembly=Corina.Controls.Silverlight"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                     xmlns:localViewmodel="clr-namespace:Corina.Cydee.Apphub.Viewmodels"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:navigation="clr-namespace:Corina.Cydee.Apphub.Base"
                     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                     xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                     d:DesignHeight="480"
                     d:DesignWidth="640"
                     mc:Ignorable="d">

    <navigation:PageView.Resources>
        <Style x:Key="STYLE_STATUS_BUTTON" TargetType="CheckBox">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="CheckBox">
                        <Grid>
                            <Rectangle Fill="White" Opacity="0" />
                            <Path Width="12"
                                  Height="12"
                                  Margin="0,0,0,0"
                                  Data="{Binding Converter={StaticResource StringToPathGeometryConverter},
                                                 Source={StaticResource ICON_CHECK}}"
                                  Fill="{StaticResource HighlightBrush}"
                                  RenderTransformOrigin="0.5,0.5"
                                  Stretch="Uniform"
                                  Visibility="{Binding IsChecked,
                                                       Converter={StaticResource BooleanToVisibilityConverter},
                                                       RelativeSource={RelativeSource TemplatedParent}}">
                                <Path.RenderTransform>
                                    <TransformGroup>
                                        <TransformGroup.Children>
                                            <RotateTransform Angle="0" />
                                            <ScaleTransform ScaleX="1" ScaleY="1" />
                                        </TransformGroup.Children>
                                    </TransformGroup>
                                </Path.RenderTransform>
                            </Path>
                            <Path Width="12"
                                  Height="12"
                                  Margin="0,0,0,0"
                                  Data="{Binding Converter={StaticResource StringToPathGeometryConverter},
                                                 Source={StaticResource ICON_CLOSE}}"
                                  Fill="{StaticResource ControlsValidationBrush}"
                                  RenderTransformOrigin="0.5,0.5"
                                  Stretch="Uniform"
                                  Visibility="{Binding IsChecked,
                                                       Converter={StaticResource BooleanToVisibilityInverseConverter},
                                                       RelativeSource={RelativeSource TemplatedParent}}">
                                <Path.RenderTransform>
                                    <TransformGroup>
                                        <TransformGroup.Children>
                                            <RotateTransform Angle="0" />
                                            <ScaleTransform ScaleX="1" ScaleY="1" />
                                        </TransformGroup.Children>
                                    </TransformGroup>
                                </Path.RenderTransform>
                            </Path>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </navigation:PageView.Resources>

    <navigation:PageView.DataContext>
        <localViewmodel:AutoResolveConfigViewmodel />
    </navigation:PageView.DataContext>

    <Grid x:Name="LayoutRoot">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="auto" />
                </Grid.ColumnDefinitions>
                <sdk:AutoCompleteBox ItemsSource="{Binding DeviceKindCollection}"
                                     MinimumPrefixLength="0"
                                     SelectedItem="{Binding SelectedDeviceKind,
                                                            Mode=TwoWay}"
                                     ValueMemberPath="Name"
                                     be:AutoCompleteBoxHelper.OtherPaths="Name,Description">
                    <sdk:AutoCompleteBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" />
                        </DataTemplate>
                    </sdk:AutoCompleteBox.ItemTemplate>
                    <i:Interaction.Triggers>
                        <be:AutoCompleteBoxTrigger>
                            <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                        </be:AutoCompleteBoxTrigger>
                    </i:Interaction.Triggers>
                </sdk:AutoCompleteBox>
                <TextBlock Grid.Column="1"
                           VerticalAlignment="Center"
                           Text="  设备序列号：" />
                <TextBox Grid.Column="2" Text="{Binding SearchDeviceSn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    <i:Interaction.Triggers>
                        <be:TextBoxEnterKeyTrigger>
                            <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                        </be:TextBoxEnterKeyTrigger>
                    </i:Interaction.Triggers>
                </TextBox>


                <Button Grid.Column="5"
                        Width="24"
                        Height="24"
                        Margin="12,0"
                        HorizontalAlignment="Left"
                        Command="{Binding LoadCommand}"
                        Style="{StaticResource RefreshButton}" />

                <Button Grid.Column="6"
                        MinWidth="60"
                        Command="{Binding InsertCommand}"
                        Content="新增" />
            </Grid>

            <toolkit:BusyIndicator Grid.Row="1"
                                   BusyContent="{StaticResource IDS_BUSYCONTENT_LOADING}"
                                   IsBusy="{Binding IsBusy}">
                <sdk:DataGrid Margin="0,12"
                              AutoGenerateColumns="False"
                              CanUserSortColumns="False"
                              ColumnWidth="*"
                              IsReadOnly="True"
                              ItemsSource="{Binding ItemsCollection}">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn Width="60"
                                                Binding="{Binding ItemIndex}"
                                                Header="序号" />
                        <sdk:DataGridTextColumn Width="120"
                                                Binding="{Binding DeviceSn}"
                                                Header="设备序列号" />
                        <sdk:DataGridTextColumn MinWidth="120"
                                                Binding="{Binding Kind}"
                                                Header="设备分类" />
                        <sdk:DataGridTemplateColumn Width="100" Header="状态">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox HorizontalAlignment="Left"
                                              Command="{Binding Path=DataContext.ChangeCommand,
                                                                RelativeSource={RelativeSource AncestorType=navigation:PageView}}"
                                              CommandParameter="{Binding }"
                                              Content="自动解析"
                                              IsChecked="{Binding AutoResolve}"
                                              Style="{StaticResource STYLE_STATUS_BUTTON}" Margin="6,0"/>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>

                        <sdk:DataGridTemplateColumn Width="100" Header="删除">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <HyperlinkButton Command="{Binding Path=DataContext.RemoveCommand,
                                                                       RelativeSource={RelativeSource AncestorType=navigation:PageView}}"
                                                     CommandParameter="{Binding Id}"
                                                     Content="删除" />
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>
            </toolkit:BusyIndicator>

            <StackPanel Grid.Row="2"
                        HorizontalAlignment="Right"
                        Orientation="Horizontal">
                <Button Command="{Binding FirstPageCommand}" Style="{StaticResource FirstPageButtonStyle}" />
                <Button Margin="12,0"
                        Command="{Binding PreviousPageCommand}"
                        Style="{StaticResource PreviousPageButtonStyle}" />
                <TextBlock Margin="12,0" VerticalAlignment="Center">
                    <Run Text="{Binding Index}" />
                    <Run Text="/" />
                    <Run Text="{Binding PagesCount}" />
                </TextBlock>
                <Button Margin="12,0"
                        Command="{Binding NextPageCommand}"
                        Style="{StaticResource NextPageButtonStyle}" />
                <Button Command="{Binding LastPageCommand}" Style="{StaticResource LastPageButtonStyle}" />
            </StackPanel>
        </Grid>

        <controls:PromptDialog Title="新增"
                               HorizontalContentAlignment="Stretch"
                               VerticalContentAlignment="Stretch"
                               CloseCommand="{Binding CancelCommand}"
                               Visibility="{Binding ShowUpdate,
                                                    Converter={StaticResource BooleanToVisibilityConverter}}"
                               WindowHeight="240"
                               WindowWidth="400">
            <Grid Margin="12,0">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <ScrollViewer>
                    <StackPanel>
                        <TextBlock Text="设备序列号" />
                        <TextBox Text="{Binding DeviceSn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>
                </ScrollViewer>
                <StackPanel Grid.Row="1"
                            HorizontalAlignment="Right"
                            Orientation="Horizontal">
                    <Button Width="60"
                            Margin="12,0"
                            Command="{Binding SubmitCommand}"
                            Content="提交" />
                    <Button Width="60"
                            Command="{Binding CancelCommand}"
                            Content="取消" />
                </StackPanel>
            </Grid>
        </controls:PromptDialog>
    </Grid>
</navigation:PageView>
